package web.beans;

import ejb.entities.Event;
import ejb.facade.EventFacade;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import javax.faces.context.FacesContext;
import javax.inject.Inject;


@ViewScoped
@Named("managerBean")
public class ManageEvent implements Serializable{
    
        private static final long serialVersionUID = 1L;
    
        @EJB
	private EventFacade evFacade;      
        
        @Inject
	private Login login;
        
        private Event selectedEvent;
        private List<Event> eventList;
        
        @PostConstruct
        public void init(){
            this.eventList=evFacade.findEventByCreatorAfterToday(login.getUser());
        }
        
    //GETTER Function       

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public EventFacade getEvFacade() {
        return evFacade;
    }

    public Event getSelectedEvent() {
        return selectedEvent;
    }

    public List<Event> getEventList() {
        return eventList;
    }        
  
    //SETTER Function

    public void setEvFacade(EventFacade evFacade) {
        this.evFacade = evFacade;
    }

    public void setSelectedEvent(Event selectedEvent) {
        this.selectedEvent = selectedEvent;
    }

    public void setEventList(List<Event> eventList) {
        this.eventList = eventList;
    }


    //BEAN Functions
    public void goToEditEvent(Event e){
        redirect("user_addNewEvent.xhtml", e);
    }

    public void redirect(String outcome, Event e) {
        login.setEventSelected(e.getIdEvent());
        FacesContext facesContext = FacesContext.getCurrentInstance();
        facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, outcome);
    }
}
